package com.example.webfilter;

import org.springframework.core.annotation.Order;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

/**
 * webflux中没有intercepter的概念，可以用webFilter代替
 * 参考：https://www.iteye.com/blog/wanshi-2409097
 */
@Component
@Order(1)
public class MyWebFilter implements WebFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
        ServerHttpRequest request =  serverWebExchange.getRequest();
        System.out.println(request.getLocalAddress());
        System.out.println("这是一个filter");
        return webFilterChain.filter(serverWebExchange);
    }
}
